/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.clinicplus.manager;

import br.com.foxline.clinicplus.entity.SystemUser;
import br.com.foxline.clinicplus.service.SystemUserService;
import br.com.foxline.clinicplus.util.Msg;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author roniere
 */
@ManagedBean
@ViewScoped
public class ManagerUserAdmin {

    @EJB
    SystemUserService userService;
    private SystemUser user;
    private String passwdnew;
    private Boolean admin;
    
    @PostConstruct
    public void init() {
        admin = true;
//        if(!userService.verifyAdmin()){
//            Msg.messagemError("Usuário não é administrador!");
//            admin = false;
//            return;
//        }
        Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
        String userEdit = params.get("usereditpassword");
        user = userService.find(Long.parseLong(userEdit));
    }

    public void update() {
        if(admin){
            userService.updateUserAdmin(passwdnew, user);
        }
    }

    public String getPasswdnew() {
        return passwdnew;
    }

    public void setPasswdnew(String passwdnew) {
        this.passwdnew = passwdnew;
    }

    public SystemUser getUser() {
        return user;
    }

    public void setUser(SystemUser user) {
        this.user = user;
    }

    public Boolean getAdmin() {
        return admin;
    }
    
}
